<!--创建"收货人详细"标签-->
<#assign consigneeDetailTag = newTag("consigneeDetailTag") />
<!--调用“收货人详细”标签-->
<#assign consigneeDetail = consigneeDetailTag('{"addressid":"${addressid}"}') />
<script type="text/javascript" src="${ctx}/statics/e_tools/js/jquery.addressSelect-1.0.js"></script>

<div class="form_wrap">
    <div class="addr_hide_wp">
        <form id="member_addr" class="validate" action="" method="post">
            <input type="hidden" name="addr_id" value="${consigneeDetail.addr_id}"/>
            <div class="addr_input_wp">
                <span>默认收货地址</span>
                <label>
                    <input type="radio" value="0" name="def_addr"> 否 </label>
                <label>
                    <input type="radio" value="1" name="def_addr"> 是 </label>
            </div>
            <div class="addr_input_wp">
					<span style="padding-right: 18px;">
					<i>*</i>收货人</span>
                <input class="addr_name" type="text" value="${consigneeDetail.name!''}" name="name" maxlength="9"/>
            </div>
            <div class="addr_input_wp">
                <span><i>*</i>手机</span>
                <input class="addr_mobile input_add" type="text" name="mobile" value="${consigneeDetail.mobile!''}"
                       maxlength="11"/>
            </div>
            <div class="addr_input_wp">
                <span><i> &nbsp;</i>固话</span>
                <input class="addr_tel input_add" type="text" name="tel" value="${consigneeDetail.tel!''}"
                       maxlength="13"/>
            </div>
            <div class="addr_input_wp" style="overflow:visible;clear:both;width:100%;height:28px;">
                <span><i>*</i>地区</span>
                <div id="selectAddress" class="address-box" style="display:block;float:left;">
                    <script type="text/javascript">
                        $(function () {
                            $('#selectAddress').addressSelect({
                                deData: [${consigneeDetail.province_id!''}, ${consigneeDetail.city_id!''}, ${consigneeDetail.region_id!''}, ${consigneeDetail.town_id!''}]
                            });
                        })
                    </script>
                </div>
            </div>
            <div class="addr_input_wp">
                <span><i>*</i>地址</span>
                <input class="input_add addr_ads gray_unable" type="text" name="addr" value="${consigneeDetail.addr!''}"
                       maxlength="60"/>
            </div>
            <div class="addr_input_wp">
                <span><i>*</i>地址别名</span>
                <input name="shipAddressName" isrequired="true" id="alias" class="input_add addr_ads gray_unable"
                       type="text" maxlength="20" placeholder="地址别名，便于标识"
                       value="${consigneeDetail.shipAddressName!''}"/>
                <span>
	                        <a href="javascript: void(0);" class="example-aliases">家里</a>
	                        <a href="javascript: void(0);" class="example-aliases">公司</a>
	                        <a href="javascript: void(0);" class="example-aliases">学校</a>
                   		 </span>
            </div>
            <div class="btns_info btn-div">
                <input class="btn_save green-btn" type="button" id="address_edit" value="保存修改"
                       rel="${consigneeDetail.addr_id}"/>
            </div>
        </form>
    </div>
</div>
<script>
    $(function () {
        //  添加别名
        $(".example-aliases").on('click', function () {
            var _val = $(this).html();
            $("#alias").val(_val);
        });
        /*修改地址专用*/
        $("#address_edit").on('click', function () {
            //校验用户名
            var membername = $(".addr_name").val();
            if (membername.indexOf(" ") != -1) {
                $.message.error("请确保会员名称前、后或名称中有空格");
                return false;
            }
            if ($(".addr_name").val() == "") {
                $.message.error("请输入联系人姓名");
                return false;
            }

            //校验收货地址
            if ($(".addr_mobile").val() == "") {
                $.message.error("手机未填写");
                return false;
            }
            //判断手机格式
            if ($(".addr_mobile").val() != "") {
                var tel = $(".addr_mobile").val();
                var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
                if (reg.test(tel) == false) {
                    $.message.error("手机格式错误");
                    return false;
                }
            }

            if ($(".addr_tel").val() != "") {
                var tel = $(".addr_tel").val();
                var reg = /^([0-9-]+)$/;
                if (!reg.test(tel)) {
                    $.message.error("电话格式错误");
                    return false;
                }
            }
            //判断收货地址
            if ($("#region_id").val() == "0") {
                $.message.error("请选择收货地址");
                return false;
            }

            //判断收货详细地址
            if ($(".addr_ads").val() == "") {
                $.message.error("请输入详细地址");
                return false;
            }

            var editid = $(this).attr("rel");
            $(".validate").ajaxSubmit({
                url     : "${ctx}/api/shop/member-address/edit.do?addr_id=" + editid,
                dataType: 'json',
                success : function (data) {
                    if (data.result == 1) {
                        $.message.success(data.message, function () {
                            location.href = "address.html"
                        })
                    }
                },
                error   : function (e) {
                    $.message.error("出现错误 ，请重试");
                }
            })
        });
    })
</script>
<style>
    .example-aliases {
        float: left;
        display: block;
        width: 35px;
        height: 20px;
        margin-right: 5px;
        line-height: 20px;
        text-align: center;
        background-color: #ffffff;
        border: 1px solid #ccc;
    }
</style>